package com.doliere.android.app.p2p.providers;

import java.util.Enumeration;
import java.util.Hashtable;

import com.doliere.android.app.p2p.services.P2pService;

import android.annotation.SuppressLint;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.net.wifi.p2p.WifiP2pDevice;
import android.provider.BaseColumns;

public class P2pDataProvider extends ContentProvider{
	
	private P2pService mService;
	private static String mDeviceName = "DEVICE_NAME";
	private static String mDeviceAddress = "ADDRESS";
	private static String mDeviceStatus = "STATUS";
	private static String mID = BaseColumns._ID;
	
	public P2pDataProvider(P2pService service){
		mService = service;
	}
	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean onCreate() {
		// TODO Auto-generated method stub
		return false;
	}

	@SuppressLint("NewApi")
	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		MatrixCursor mc = new MatrixCursor(new String[]{mDeviceName, mDeviceAddress, mDeviceStatus});
		Hashtable<String, WifiP2pDevice> devices = mService.getDnsDevices();
		Enumeration<String> en = devices.keys();
		long id = 0;
		while(en.hasMoreElements()){
			
			String[] row = new String[4];
			WifiP2pDevice dev = devices.get(en.nextElement());
			id++;
			row[0] = id + "";
			row[1] = dev.deviceName;
			row[2] = dev.deviceAddress;
			row[3] = dev.status + "";
			mc.addRow(row);
		}
		return mc;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

}
